﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.FastSearch.SharePoint.Interfaces;

namespace Com.FastSearch.SharePoint.BL.SearchManager
{
    public class FQLQueryBuilder:IQueryBuilder
    {

        private static IQueryBuilder _instance = null;

        #region IQueryBuilder Members

        public static IQueryBuilder Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new FQLQueryBuilder();
                }
                return _instance;
            }
        }

        public string BuildQueryStringFromTemplate(string queryString, string queryTemplate)
        {
            if (queryTemplate == null)
            {
                return "";
            }
            if (queryString == null)
            {
                queryString = "";
            }

            return string.Format(queryTemplate, queryTemplate.IndexOf('"') >= 0 ? queryString.Replace("\\", "\\\\").Replace("\"", "\\\"") : queryString, "user");
            
        }

        #endregion
    }
}
